package com.naml.b_sellticket;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/26 17:24
 * @desc 使用继承Thread类实现窗口卖票
 */
@SuppressWarnings("all")
public class ThreadSellTicket01 {
    public static void main(String[] args) {
        SellTicket01 sellTicket01 = new SellTicket01();
        SellTicket01 sellTicket02 = new SellTicket01();
        SellTicket01 sellTicket03 = new SellTicket01();
        sellTicket01.start();
        sellTicket02.start();
        sellTicket03.start();
    }
}
class SellTicket01 extends Thread {
    //由于继承方式，所以定义static用来多线程共享数据
    private static int count = 100;
    @Override
    public void run() {
        while(true){
            if (count <= 0) {
                break;
            }
            try {
                Thread.sleep(500);
                System.out.println("窗口"+Thread.currentThread().getName() +"：卖票，剩余张数："+(--count));
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
